package com.asm.code;

import android.graphics.Bitmap;
import android.util.Log;
import com.miqt.plugin.inject.annotation.After;
import java.io.Closeable;
import leakcanary.AppWatcher;

/**
 * 插桩配置类，同时也是插桩后的回调类，最少知识原则
 */
public class LeakWatcher {
    static String TAG = "LeakWatcher";

    @After(clazz = Closeable.class, method = "close")
    public static void onCloseableClose(Closeable closeable) {
        Log.d(TAG, "onCloseableClose");
        String desc =  Log.getStackTraceString(new Throwable("watcher Closeable leaked"));
        AppWatcher.INSTANCE.getObjectWatcher().expectWeaklyReachable(closeable,desc);
    }
    @After(clazz = Bitmap.class, method = "recycle")
    public static void onBitmapRecycle(Bitmap bitmap) {
        Log.d(TAG, "onBitmapRecycle");
        String desc =  Log.getStackTraceString(new Throwable("watcher Bitmap leaked"));
        AppWatcher.INSTANCE.getObjectWatcher().expectWeaklyReachable(bitmap,desc);
    }
}
